package org.example.xsda.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import org.example.xsda.common.Result;
import org.example.xsda.service.StatisticsService;
import org.example.xsda.vo.StatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 统计控制器
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @GetMapping
    @SaCheckRole(value = {"admin", "teacher"}, mode = SaMode.OR)
    public Result<StatisticsVO> getStatistics() {
        try {
            StatisticsVO statistics = statisticsService.getStatistics();
            return Result.success(statistics);
        } catch (Exception e) {
            e.printStackTrace(); // 打印完整堆栈
            return Result.error("获取统计数据失败：" + e.getMessage());
        }
    }
}

